﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace T.FAS.Runtime.ScheduleJob.SPI
{
    /// <summary>
    /// 系统执行频率
    /// </summary>
    public class SysExecuteFrequency
    {
        public string ID { get; set; }
        public string Code { get; set; }
        [International]
        public string Name { get; set; } 
        [International]
        public string Description { get; set; }
        public bool IsEnable { get; set; }
        public int SortOrder { get; set; }
        public string CronExpression { get; set; }
        [International]
        public string FrequencyContent { get; set; }
        private Dictionary<string, string> _frequencyContentDic = null;
        public Dictionary<string, string> FrequencyContentDic
        {
            get
            {
                if (_frequencyContentDic == null)
                {
                    if (!string.IsNullOrEmpty(FrequencyContent))
                    {
                        _frequencyContentDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(FrequencyContent);
                    }
                }
                return _frequencyContentDic;
            }
        }      
        /// <summary>
        /// 用于管理时界面展示
        /// </summary>
        public string DayValue
        {
            get
            {
                if (FrequencyContentDic!=null && FrequencyContentDic.ContainsKey("DayValue"))
                {
                    return FrequencyContentDic["DayValue"];
                }
                return "";
            }
        }
        /// <summary>
        /// 用于管理时界面展示
        /// </summary>
        public string HourValue
        {
            get
            {
                if (FrequencyContentDic != null && FrequencyContentDic.ContainsKey("HourValue"))
                {
                    return FrequencyContentDic["HourValue"];
                }
                return "";
            }
        }

        public void CopyTo(SysExecuteFrequency targetData)
        {
            if (targetData == null)
                targetData = new SysExecuteFrequency();
            if(string.IsNullOrEmpty(targetData.ID))
                targetData.ID = this.ID;
            targetData.Code = this.Code;
            targetData.Name = this.Name;
            targetData.Description = this.Description;
            targetData.IsEnable = this.IsEnable;
            targetData.SortOrder = this.SortOrder;
            targetData.CronExpression = this.CronExpression;
            targetData.FrequencyContent = this.FrequencyContent;
        }
    }
}
